package org.eclipse.jet.internal.taglib.custom;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jet.taglib.CustomTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInstanceFactory;

/**
 * Tag Factory for customTags
 */
public class TagFactory implements TagInstanceFactory
{

  private final Map tagOrdinalByName;
  
  /**
   * 
   */
  public TagFactory()
  {
    tagOrdinalByName = new HashMap(30);

    tagOrdinalByName.put("setTag",new Integer(1)); //$NON-NLS-1$
    tagOrdinalByName.put("empty",new Integer(2)); //$NON-NLS-1$
    tagOrdinalByName.put("contain",new Integer(3)); //$NON-NLS-1$
    tagOrdinalByName.put("condition",new Integer(4)); //$NON-NLS-1$
    tagOrdinalByName.put("loop",new Integer(5)); //$NON-NLS-1$
  }

  public CustomTag createCustomTag(String name)
  {
    Integer ordinal = (Integer)tagOrdinalByName.get(name);
    
    switch(ordinal == null ? 0 : ordinal.intValue()) {
      case 1:
      return new org.eclipse.jet.internal.taglib.custom.SetTagTag();
        
      case 2:
      return new org.eclipse.jet.internal.taglib.custom.EmptyTag();
        
      case 3:
      return new org.eclipse.jet.internal.taglib.custom.ContainTag();
      
      case 4:
      return new org.eclipse.jet.internal.taglib.custom.ConditionTag();
      
      case 5:
      return new org.eclipse.jet.internal.taglib.custom.LoopTag();
      
      default:
        throw new JET2TagException("Unknown Tag: " + name); //$NON-NLS-1$
    }
  }

  public String libraryId()
  {
    return "org.eclipse.jet.customTags";
  }
  
}
